(function($) {
	var methods = {
		checkItemInGroup : function(checkIds, id) {
			if (checkIds == null) {
				return false;
			}
			var ids = checkIds.split(",");
			return $.inArray(id, ids) > -1;
		},
		formatTime : function(obj, defaultTime) {
			var s = "";
			if (obj.indexOf("-") > -1) {
				f = obj.substring(0, obj.indexOf("-"));
				m = obj.substring(obj.indexOf("-") + 1, obj.lastIndexOf("-"));
				e = obj.substring(obj.lastIndexOf("-") + 1);
				s = f + m + e;
			}

			if (obj.indexOf(".") > -1) {
				hh = obj.substring(0, obj.indexOf("."));
				mm = obj.substring(obj.indexOf(".") + 1, obj.lastIndexOf("."));
				ss = obj.substring(obj.lastIndexOf(".") + 1);
				s += hh + mm + ss;
			} else if (defaultTime != null) {
				s += defaultTime;
			}

			return s;
		},
		formatDate : function(obj, defaultTime) {
			var s = "";
			if (obj.indexOf("-") > -1) {
				f = obj.substring(0, obj.indexOf("-"));
				m = obj.substring(obj.indexOf("-") + 1, obj.lastIndexOf("-"));
				e = obj.substring(obj.lastIndexOf("-") + 1);
				s = f + m + e;
			}

			return s;
		},
		parseTime : function(obj, defaultTime) {
			var s = "";
			if (obj.length == 8) {
				f = obj.substring(0, 4);
				m = obj.substring(4, 6);
				e = obj.substring(6, 8);
				s = f + "-" + m + "-" + e;
			} else if (obj.length == 14) {
				f = obj.substring(0, 4);
				m = obj.substring(4, 6);
				e = obj.substring(6, 8);
				h = obj.substring(8, 10);
				mm = obj.substring(10, 12);
				ss = obj.substring(12, 14);
				s = f + "-" + m + "-" + e + " " + h + ":" + mm + ":" + ss;
			}

			return s;
		},
		parseDate : function(obj, defaultTime) {
			var s = "";
			if (obj.length >= 8) {
				f = obj.substring(0, 4);
				m = obj.substring(4, 6);
				e = obj.substring(6, 8);
				s = f + "-" + m + "-" + e;
			}

			return s;
		},
		findForItem : function(items, forItem) {
			var s;
			$.each(items, function(i, m) {
						if (m.formName == forItem) {
							s = m;
							return false;
						}
					});
			return s;
		}
	}

	/**
	 * for edit id 主键 tableName 表名称 viewId 视图id selfFunc 视图初始化
	 */
	$.grooveViewPre = function(id, tableName, viewId, selfFunc) {
		$.ajax({
					type : 'post',
					url : context + '/system/baseworkselect.do',
					data : {
						id : id,
						tableName : tableName
					},// 可以直接加一个函数名。
					dataType : 'json',
					async : false,
					success : function(data) {
						if (viewId != null) {
							var gv = new $.grooveView(viewId, selfFunc,
									(data.success ? data.data : {}));
						}
					}
				});
	}

	/**
	 * for edit jsonparams 数据选择参数 viewId 视图id selfFunc 视图初始化
	 * 
	 * jsonparams ： { id : "01", primaryTable : "primaryTest", foreignTables : [
	 * {foreignTable : "foreignTest1", orderby : "columnTest1", sort : "ASC" },{
	 * foreignTable : "foreignTest2", orderby : "columnTest2", sort : "DESC" }] }
	 * 
	 */
	$.grooveViewPreII = function(params, viewId, selfFunc) {
		$.ajax({
					type : 'post',
					url : context + '/system/baseworkselectII.do',
					data : {
						jsonparams : JSON.stringify(params)
					},// 可以直接加一个函数名。
					dataType : 'json',
					async : false,
					success : function(data) {
						if (data.success == false) {
							alert(data.errorMsg);
						} else {
							var gv = new $.grooveView(viewId, selfFunc,
									(data.success ? data.resultData : {}));
						}
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
						alert(XMLHttpRequest)
					}
				});
	}

	/* for add */
	$.grooveView = function(viewId, selfFunc, dataBean) {
		$.ajax({
			type : 'post',
			url : context + '/system/tableview.do?method=init',
			data : {
				id : viewId
			},// 可以直接加一个函数名。
			dataType : 'json',
			async : false,
			beforeSend : function() {
				/*
				 * $("body") .prepend("<div id=\"dialogValidateTips\"
				 * title=\"页面初始化错误信息\"></div>");
				 */

				if (selfFunc.beforecall != null) {
					selfFunc.beforecall.apply();
				}

				$("<div>", {
							id : "dialogValidateTips",
							title : "页面初始化错误信息"
						}).appendTo("body");

				$("#dialogValidateTips").dialog({
							autoOpen : false,
							width : 600,
							height : 300,
							modal : false,
							closeOnEscape : true,
							resizable : true,
							// hide : "explode",
							// show : "slow",
							buttons : [{
										text : " 关闭 ",
										click : function() {
											$(this).dialog("close");
										}
									}]
						});

				$("<div>", {
							id : "dialogSubmitOkTips",
							title : "操作成功提示窗口"
						}).append("<p>"
						+ (selfFunc.OKMessage == null
								? "已成功提交数据信息"
								: selfFunc.OKMessage) + "</p>")
						.appendTo("body");

				$("#dialogSubmitOkTips").dialog({
							autoOpen : false,
							width : 400,
							height : 200,
							modal : true,
							closeOnEscape : true,
							resizable : true,
							// hide : "explode",
							// show : "slow",
							buttons : [{
										text : " 确定 ",
										click : function() {
											$(this).dialog("close");
											if (selfFunc.aftercall != null) {
												selfFunc.aftercall.apply();
											}
										}
									}]
						});

				$("<div>", {
							id : "dialogSubmitKOTips",
							title : "错误提示窗口"
						}).append("<p></p>").appendTo("body");

				$("#dialogSubmitKOTips").dialog({
							autoOpen : false,
							width : 400,
							height : 200,
							modal : true,
							closeOnEscape : true,
							resizable : true,
							// hide : "explode",
							// show : "slow",
							buttons : [{
										text : " 确定 ",
										click : function() {
											$(this).dialog("close");
										}
									}]
						});

				$("<div>", {
							id : "dialogSubmitTips",
							title : "提交确认窗口"
						}).append("<p>"
						+ (selfFunc.submitMessage == null
								? "您确定要提交保存当前页面信息?"
								: selfFunc.submitMessage) + "</p>")
						.appendTo("body");

				$("#dialogSubmitTips").dialog({
					autoOpen : false,
					width : 400,
					height : 200,
					modal : true,
					closeOnEscape : true,
					resizable : false,
					// hide : "explode",
					// show : "slow",
					buttons : [{
						id : "dialogSubmitButton",
						text : " 确定 ",
						click : function() {
							var thisForm = $("#" + selfFunc.formID);

							var options = {
								beforeSubmit : function(formData, jqForm,
										options) {
									/*
									 * var queryString = $.param(formData);
									 * alert($("#fcindustry").val());
									 */
									return true;
								},
								success : function showResponse(responseText,
										statusText) {

									/*
									 * alert('status: ' + statusText +
									 * '\n\nresponseText: \n' + responseText +
									 * '\n\n');
									 */

									if (responseText.success) {
										$("#dialogSubmitTips").dialog("close");
										$("#dialogSubmitOkTips").dialog("open");
									} else {
										$("#dialogSubmitTips").dialog("close");
										$("#dialogSubmitKOTips").find("p")
												.html(responseText.msg);
										$("#dialogSubmitKOTips").dialog("open");
									}
								},
								error : function(XMLHttpRequest, textStatus,
										errorThrown) {
									//
								},
								url : context + "/system/baseworkremix.do", // override
								// contentType : "application/json",
								type : "post",
								// async : false,
								// attribute
								// dataType : 'json', // 'xml', 'script', or
								// 'json'
								// (expected server
								// response type)
								// clearForm : true
								// clear all form fields after successful submit
								resetForm : true,
								// reset the form after
								// successful submit
								// $.ajax options can be used here too, for
								// example:
								// timeout: 3000
								iframe : (thisForm.attr("enctype") == "multipart/form-data")
							};

							thisForm.ajaxSubmit(options);
						}
					}, {
						text : " 取消 ",
						click : function() {
							$(this).dialog("close");
						}
					}]
				});

				$("#" + selfFunc.formID).validationEngine({
					validationEventTriggers : "blur",
					inlineValidation : true,
					success : false,
					promptPosition : "bottomRight",
					submitButtonID : selfFunc.submitButtonID,
					submitButtonFunc : function(r) {
						if (r) {
							$("#" + selfFunc.formID).checkBox($("#"
									+ selfFunc.formID));
							$("#dialogSubmitTips").dialog("open");
						}
					}
				});
			},
			success : function(data) {
				if (data.success == false) {
					if (data.errorMsg == "-1") {
						alert("未找到视图定义<" + viewId + ">");
					} else if (data.errorMsg == "-2") {
						alert("没有使用视图的权限");
					}
				} else {
					var validateTxt = '';

					var tableNames = data.primaryTable;
					var counterNames = data.primaryTableCounterName;
					var handleTypes = data.primaryTableHandleType;
					var viewListener = data.listener;

					$("<span>", {
								id : data.primaryTableColumnFormName
							}).appendTo($("#" + selfFunc.formID));

					$("<input>", {
								type : "hidden",
								id : "listener",
								name : "listener",
								value : viewListener
							}).appendTo($("#" + selfFunc.formID));

					if (data.foreignTables != null) {
						$.each(data.foreignTables, function(i, n) {
									tableNames += "," + n.foreignTable;
									counterNames += ","
											+ n.foreignTableCounterName;
									handleTypes += ","
											+ n.foreignTableHandleType;
								});
					}

					$("<input>", {
								type : "hidden",
								id : "tableNames",
								name : "tableNames",
								value : tableNames
							}).appendTo($("#" + selfFunc.formID));

					$("<input>", {
								type : "hidden",
								id : "counterNames",
								name : "counterNames",
								value : counterNames
							}).appendTo($("#" + selfFunc.formID));

					$("<input>", {
								type : "hidden",
								id : "handleTypes",
								name : "handleTypes",
								value : handleTypes
							}).appendTo($("#" + selfFunc.formID));

					/*
					 * $(data.component).each(function(i) { if ($("#" +
					 * data.component[i].formName).length > 0) { $("item #" +
					 * data.component[i].formName)
					 * .assemblingItem(data.component[i]); } else { validateTxt += "<div>item[" +
					 * data.component[i].formName + "] not found in form.</div>"; }
					 * });
					 */

					/* init component */
					if (data.component != null) {
						$.each(data.component, function(i, n) {

									if ($("span[id=" + n.formName + "]").length > 0) {
										$("span[id=" + n.formName + "]")
												.assemblingItem(
														n,
														(dataBean != null
																? dataBean[n.name]
																: null));
									} else {
										validateTxt += "<div>span["
												+ n.formName
												+ "] not found in form.</div>";
									}
								});
					}

					/* init list */
					if (data.componentInList != null) {
						$.each(data.componentInList, function(i, n) {
							if ($("#" + n.id).length > 0) {
								$("#" + n.id).attr("counter_", "0");

								var thead = $("<thead>");

								var theadtbatr = $("<tr>");
								// theadtbatr.attr("class", "ui-widget-header");
								thead.append(theadtbatr);
								var theadtbatd = $("<th>");
								theadtbatd.attr("align", "left");
								theadtbatd
										.attr("colspan", (n.items.length + 1));
								theadtbatd.css("margin-left", "10px");

								var addBtn = $("<a id=\""
										+ n.id
										+ "_tbr\" href=\"javascript:void(0);\">增加</a>");
								addBtn.bind("click", function() {
											/* 清空当前正在编辑的行序列号 */
											$("#" + n.id)
													.attr("nowEditIdx", "");
											$(this).initDialog4List(n);
										});

								theadtbatd.append(addBtn);

								theadtbatd.append($("<input>", {
											"type" : "hidden",
											"value" : "",
											"name" : n.counterName,
											"id" : n.counterName
										}));

								theadtbatr.append(theadtbatd)

								$("#" + n.id).append(thead);

								var thead1 = $("<thead>");
								var theadtr = $("<tr>");
								theadtr.attr("class", "ui-widget-header");
								thead1.append(theadtr);
								$("#" + n.id).append(thead1);
								$.each(n.items, function(j, m) {
											if (m.type == "hidden") {
												// do nothing
											} else {
												var theadtrtd = $("<th>");
												theadtrtd.attr("class", m.name);
												theadtrtd.css("text-align",
														"center");
												theadtrtd.attr("width",
														m.param.width);
												theadtrtd.html(m.label);
												theadtr.append(theadtrtd);
											}
										});
								var theadtrtd = $("<th>");
								theadtrtd.css("text-align", "center");
								theadtrtd.html("操作");
								theadtr.append(theadtrtd);

								var tbody = $("<tbody>");
								$("#" + n.id).append(tbody);

								if (dataBean != null
										&& dataBean[n.id].length > 0) {
									$.each(dataBean[n.id], function(j, info) {
										var counter_ = parseInt($("#" + n.id)
												.attr("counter_"));
										var trid = n.id + "_tr_" + counter_;
										var idx = counter_;
										var tbodytr = $("<tr>", {
													"id" : trid
												});
										tbodytr.attr("idx", idx);
										$("#" + n.id + ">tbody")
												.append(tbodytr);

										$("<input>", {
											"type" : "hidden",
											"name" : data.foreignTables[n.forTable].foreignTableColumnFormName
													+ "_" + counter_,
											"value" : info[data.foreignTables[n.forTable].foreignTableColumn]
										}).appendTo(tbodytr);

										$.each(n.items, function(j, m) {
											if (m.type == "hidden") {
												tbodytr.append("<input>", {
															"type" : "hidden",
															"name" : m.formName
																	+ "_"
																	+ counter_,
															value : info[m.name]
														});
											} else {
												var span = $("<span>");
												if (m.type == "radio"
														|| m.type == "checkbox"
														|| m.type == "select"
														|| m.type == "combobox") {
													var forItem = findForItem(
															n.items, m.forItem);
													if (forItem != null) {
														span
																.html(info[forItem.name]);
													} else {
														span.html(info[m.name]);
													}
												} else {
													span.html(info[m.name]);
												}

												var tdid = n.id + "_tr_"
														+ counter_ + "_td_"
														+ m.formName;
												var tbodytrtd = $("<td>", {
															id : tdid,
															align : "center"
														});
												tbodytrtd.append(span);
												tbodytr.append(tbodytrtd);
											}
										});

										var span = $("<span>");

										var editA = $("<a>");
										span.append(editA);
										editA.attr("href",
												"javascript:void(0);");
										editA.html("编辑");
										editA.bind("click", function() {
													/* 记录当前编辑行序列 */
													$("#" + n.id).attr(
															"nowEditIdx", idx);
													$(this).initDialog4List(n);
												});
										span.append("&nbsp;");
										var eidtD = $("<a>");
										span.append(eidtD);
										eidtD.attr("href",
												"javascript:void(0);");
										eidtD.html("删除");
										eidtD.bind("click", function() {
											var param = {
												columnName : data.foreignTables[n.forTable].foreignTableColumn,
												tableName : n.forTable
											};

											param.id = info[data.foreignTables[n.forTable].foreignTableColumn];

											var selfFunc = {
												submitMessage : "您确定要删除当前信息？删除后数据将不可恢复！",
												aftercall : function() {
													$("#" + trid).remove();
													$(this).listCount(n);
												}
											};

											$.grooveDeleteII(param, selfFunc);
										});

										var tdid = n.id + "_tr_" + counter_
												+ "_td_AA";
										var tbodytrtd = $("<td>", {
													id : tdid,
													align : "center"
												});
										tbodytrtd.append(span);
										tbodytr.append(tbodytrtd);

										counter_++;

										$("#" + n.id)
												.attr("counter_", counter_);
									});

									$(this).listCount(n);
								}
							} else {
								validateTxt += "<div>list[" + n.id
										+ "] not found in form.</div>";
							}
						});
					}

					/* init dialog */
					if (data.componentInDialog != null) {
						$.each(data.componentInDialog, function(i, n) {

								});
					}

					if (validateTxt != '') {
						$("#dialogValidateTips").append(validateTxt);
						$("#dialogValidateTips").dialog("open");
					}
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				alert(XMLHttpRequest.responseText);
			}
		});
	};

	/* for delete */
	$.grooveDelete = function(param, selfFunc) {
		if (selfFunc == null) {
			selfFunc = {};
		}

		if ($("#dialogDelSubmitTips").length == 0) {
			$("<div>", {
						id : "dialogDelSubmitTips",
						title : "提交确认窗口"
					}).append("<p>"
					+ (selfFunc.submitMessage == null
							? "您确定要删除当前信息?"
							: selfFunc.submitMessage) + "</p>")
					.appendTo("body");

			$("#dialogDelSubmitTips").dialog({
						autoOpen : true,
						width : 400,
						height : 200,
						modal : true,
						closeOnEscape : true,
						resizable : false,
						// hide : "explode",
						// show : "slow",
						buttons : [{
									id : "dialogDelSubmitButton",
									text : " 确定 ",
									click : function() {

									}
								}, {
									text : " 取消 ",
									click : function() {
										$(this).dialog("close");
									}
								}]
					});
		} else {
			$("#dialogDelSubmitTips").dialog("open");
		}

		$("#dialogDelSubmitButton").bind("click", function() {
					$("#dialogDelSubmitTips").dialog("close");

					$.ajax({
								type : "POST",
								url : context + "/system/baseworkdelete.do",
								data : param,
								success : function(resultData) {
									if (resultData.success) {
										if (selfFunc.aftercall != null) {
											selfFunc.aftercall
													.apply(resultData);
										}
									} else {
										alert("删除操作出现异常," + resultData.errorMsg);
									}
								}
							});	
				});
				
		$("#dialogDelSubmitButton").unbind('click');		
	}

	/* for delete II */
	$.grooveDeleteII = function(param, selfFunc) {
		if (selfFunc == null) {
			selfFunc = {};
		}

		if ($("#dialogDelIISubmitTips").length == 0) {
			$("<div>", {
						id : "dialogDelIISubmitTips",
						title : "提交确认窗口"
					}).append("<p>"
					+ (selfFunc.submitMessage == null
							? "您确定要删除当前信息?"
							: selfFunc.submitMessage) + "</p>")
					.appendTo("body");

			$("#dialogDelIISubmitTips").dialog({
						autoOpen : true,
						width : 400,
						height : 200,
						modal : true,
						closeOnEscape : true,
						resizable : false,
						// hide : "explode",
						// show : "slow",
						buttons : [{
									id : "dialogDelIISubmitButton",
									text : " 确定 ",
									click : function() {

									}
								}, {
									text : " 取消 ",
									click : function() {
										$(this).dialog("close");
									}
								}]
					});
		} else {
			$("#dialogDelIISubmitTips").dialog("open");
		}

		$("#dialogDelIISubmitButton").bind("click", function() {
					$("#dialogDelIISubmitTips").dialog("close");
					$.ajax({
								type : "POST",
								url : context + "/system/baseworkdeleteII.do",
								data : param,
								success : function(resultData) {
									if (resultData.success) {
										if (selfFunc.aftercall != null) {
											selfFunc.aftercall
													.apply(resultData);
										}
									} else {
										alert("删除操作出现异常," + resultData.errorMsg);
									}
								}
							});
					$("#dialogDelIISubmitButton").unbind('click');
				});

	}

	var checkboxGroups = [];

	$.fn.assemblingItem = function(component, vlu) {
		var paramObj = eval(component.param);

		if (component.type == "input") {
			var ipt = $("<input>", {
						"type" : "text",
						"value" : (vlu == null ? component.defaultValue : vlu),
						"readonly" : paramObj.readOnly,
						"name" : component.formName,
						"id" : component.formName
					});
			if (paramObj.VEClassName != null
					&& $.trim(paramObj.VEClassName) != "") {
				ipt.addClass(paramObj.VEClassName);
			} else {
				ipt.addClass("text-input");
			}
			ipt.insertBefore($(this));
		} else if (component.type == "hidden") {
			$("<input>", {
						"type" : "hidden",
						"value" : vlu == null ? component.defaultValue : vlu,
						"name" : component.formName,
						"id" : component.formName
					}).insertBefore($(this));
		} else if (component.type == "textarea") {
			var txt = $("<textarea>", {
						"value" : (vlu == null ? component.defaultValue : vlu),
						"name" : component.formName,
						"id" : component.formName
					});
			if (paramObj.VEClassName != null
					&& $.trim(paramObj.VEClassName) != "") {
				txt.addClass(paramObj.VEClassName);
			} else {
				txt.addClass("text-input");
			}
			txt.insertBefore($(this));
		} else if (component.type == "date") {
			var ipt = $("<input>", {
						"type" : "text",
						"value" : (vlu == null
								? component.defaultValue
								: methods.parseDate(vlu)),
						"name" : component.formName + "_",
						"id" : component.formName + "_"
					})

			ipt.change(function() {
						// alert($(this).val());
						$("#" + component.formName).val(methods.formatTime(
								$(this).val(), "000000"));
					});

			if (paramObj.VEClassName != null
					&& $.trim(paramObj.VEClassName) != "") {
				ipt.addClass(paramObj.VEClassName);
			} else {
				ipt.addClass("validate[custom[date]] text-input datepicker");
			}

			ipt.insertBefore($(this));

			$("<input>", {
						"type" : "hidden",
						"value" : (vlu == null ? component.defaultValue : vlu),
						"name" : component.formName,
						"id" : component.formName
					}).insertBefore($(this));

			ipt.datepicker({
						// changeMonth : true,
						// changeYear : true,
						altField : "#" + component.formName,
						showWeek : true,
						regional : "zh-CN",
						showButtonPanel : true,
						dateFormat : "yy-mm-dd"
					});
		} else if (component.type == "select") {
			var selector = $("<select>", {
						"name" : component.formName,
						"id" : component.formName
					});
			// var selector = $('<select></select>');
			selector.bind("change", function() {
				// alert($(this).val() + "<--->" + $(this).text());
				$("#" + paramObj.forItem).attr("value", $(this).text());
					// $(this).children("option:selected").val()
				})
			var values = paramObj.items;

			for (var i = 0; i < values.length; i++) {
				selector.append("<option value=\"" + values[i].id + "\">"
						+ values[i].name + "</option>");
			}

			if (paramObj.VEClassName != null
					&& $.trim(paramObj.VEClassName) != "") {
				selector.addClass(paramObj.VEClassName);
			} else {
				selector.addClass("select");
			}

			selector.insertBefore($(this));
		} else if (component.type == "combobox") {

		} else if (component.type == "checkbox") {
			if (paramObj != null && paramObj.items != null) {
				checkboxGroups.push({
							itemName : component.formName,
							forItem : paramObj.forItem
						});

				var values = paramObj.items;
				for (var i = 0; i < values.length; i++) {
					var chk = $("<input>", {
								"type" : "checkbox",
								"value" : values[i].id,
								"name" : component.formName + "_idx_" + i,
								"itemName" : component.formName,
								"label" : values[i].name,
								"checked" : (methods
										.checkItemInGroup((vlu == null
														? paramObj.checkItem
														: vlu), values[i].id)
										? true
										: false),
								"id" : component.formName + "_idx_" + i
							});

					if (paramObj.VEClassName != null
							&& $.trim(paramObj.VEClassName) != "") {
						chk.addClass(paramObj.VEClassName);
					}

					chk.insertBefore($(this));

					$("<label for=\"" + (component.formName + "_idx_" + i)
							+ "\">" + values[i].name + "</label>")
							.insertBefore($(this));
				}

				$("<input>", {
							"type" : "hidden",
							"name" : component.formName,
							"id" : component.formName
						}).insertBefore($(this));
			} else {
				var chk = $("<input>", {
							"type" : "checkbox",
							"value" : component.defaultValue,
							"checked" : (vlu == null
									? component.defaultValue
									: vlu),
							"name" : component.formName,
							"label" : component.label,
							"id" : component.formName
						});

				chk.click(function() {
							if ($("#" + paramObj.forItem).length > 0) {
								if ($(this).attr("checked")) {
									$("#" + paramObj.forItem).val($(this)
											.attr("label"));
								} else {
									$("#" + paramObj.forItem).val("");
								}
							}
						});

				chk.insertBefore($(this));

				if (paramObj.VEClassName != null
						&& $.trim(paramObj.VEClassName) != "") {
					chk.addClass(paramObj.VEClassName);
				}

				$("<label for=\"" + (component.formName) + "\">"
						+ component.label + "</label>").insertBefore($(this));
			}
		} else if (component.type == "radio") {
			if (paramObj != null && paramObj.items != null) {
				var values = paramObj.items;

				for (var i = 0; i < values.length; i++) {
					var rad = $("<input>", {
						"type" : "radio",
						"value" : values[i].id,
						"name" : component.formName,
						"label" : values[i].name,
						"checked" : ((paramObj.checkItem == values[i].id || values[i].id == vlu)
								? true
								: false),
						"id" : component.formName + "_idx_" + i
					});

					rad.click(function() {
								if ($(this).attr("checked")
										&& $("#" + paramObj.forItem).length > 0) {
									$("#" + paramObj.forItem).val($(this)
											.attr("label"));
								}
							});

					if (paramObj.VEClassName != null
							&& $.trim(paramObj.VEClassName) != "") {
						rad.addClass(paramObj.VEClassName);
					}

					rad.insertBefore($(this));

					$("<label for=\"" + (component.formName + "_" + i) + "\">"
							+ values[i].name + "</label>")
							.insertBefore($(this));
				}
			} else {
				var rad = $("<input>", {
					"type" : "radio",
					"value" : component.defaultValue,
					"checked" : ((paramObj.checkItem == component.defaultValue || component.defaultValue == vlu)
							? true
							: false),
					"name" : component.formName,
					"label" : component.label,
					"id" : component.formName
				});

				rad.click(function() {
							if ($(this).attr("checked")
									&& $("#" + paramObj.forItem).length > 0) {
								$("#" + paramObj.forItem).val($(this)
										.attr("label"));
							}
						});

				if (paramObj.VEClassName != null
						&& $.trim(paramObj.VEClassName) != "") {
					rad.addClass(paramObj.VEClassName);
				}

				rad.insertBefore($(this));

				$("<label for=\"" + (component.formName) + "\">"
						+ component.label + "</label>").insertBefore($(this));

			}
		} else if (component.type == "file") {
			var file = $("<input>", {
						"type" : "file",
						"name" : component.formName,
						"id" : component.formName
					});
			if (paramObj.VEClassName != null
					&& $.trim(paramObj.VEClassName) != "") {
				file.addClass(paramObj.VEClassName);
			}

			file.insertBefore($(this));
		}

		$(this).remove();
	};

	$.fn.checkBox = function(form) {
		$(checkboxGroups).each(function(j, m) {
			var ids = "";
			var names = "";
			form.find("input:checkbox[itemName='" + m.itemName + "']").each(
					function(i, n) {
						if ($(n).attr("checked")) {
							names += $(n).attr("label") + ",";
							ids += $(n).val() + ",";
						}
					});

			$("#" + m.itemName).attr("value", ids.substring(0, ids.length - 1));
			$("#" + m.forItem).attr("value",
					names.substring(0, names.length - 1));
		});
	}

	$.fn.assemblingItem4List = function(component, vlu) {
		var paramObj = eval(component.param);

		if (component.type == "input") {
			var ipt = $("<input>", {
						"type" : "text",
						"value" : (vlu == null ? component.defaultValue : vlu),
						"readonly" : paramObj.readOnly,
						"name" : component.formName,
						"id" : component.formName
					});
			if (paramObj.VEClassName != null
					&& $.trim(paramObj.VEClassName) != "") {
				ipt.addClass(paramObj.VEClassName);
			} else {
				ipt.addClass("text-input");
			}
			ipt.insertBefore($(this));
		} else if (component.type == "hidden") {
			$("<input>", {
						"type" : "hidden",
						"value" : vlu == null ? component.defaultValue : vlu,
						"name" : component.formName,
						"id" : component.formName
					}).insertBefore($(this));
		} else if (component.type == "textarea") {
			var txt = $("<textarea>", {
						"value" : (vlu == null ? component.defaultValue : vlu),
						"name" : component.formName,
						"id" : component.formName
					});
			if (paramObj.VEClassName != null
					&& $.trim(paramObj.VEClassName) != "") {
				txt.addClass(paramObj.VEClassName);
			} else {
				txt.addClass("text-input");
			}
			txt.insertBefore($(this));
		} else if (component.type == "date") {
			var ipt = $("<input>", {
						"type" : "text",
						"value" : (vlu == null
								? component.defaultValue
								: methods.parseDate(vlu)),
						"name" : component.formName + "_",
						"id" : component.formName + "_"
					})

			ipt.change(function() {
						// alert($(this).val());
						$("#" + component.formName).val(methods.formatTime(
								$(this).val(), "000000"));
					});

			if (paramObj.VEClassName != null
					&& $.trim(paramObj.VEClassName) != "") {
				ipt.addClass(paramObj.VEClassName);
			} else {
				ipt.addClass("validate[custom[date]] text-input datepicker");
			}

			ipt.insertBefore($(this));

			$("<input>", {
						"type" : "hidden",
						"value" : (vlu == null ? component.defaultValue : vlu),
						"name" : component.formName,
						"id" : component.formName
					}).insertBefore($(this));

			ipt.datepicker({
						// changeMonth : true,
						// changeYear : true,
						altField : "#" + component.formName,
						showWeek : true,
						regional : "zh-CN",
						showButtonPanel : true,
						dateFormat : "yy-mm-dd"
					});
		} else if (component.type == "select") {
			var selector = $("<select>", {
						"name" : component.formName,
						"id" : component.formName
					});
			// var selector = $('<select></select>');
			selector.bind("change", function() {
				// alert($(this).val() + "<--->" + $(this).text());
				$("#" + paramObj.forItem).attr("value", $(this).text());
					// $(this).children("option:selected").val()
				})
			var values = paramObj.items;

			for (var i = 0; i < values.length; i++) {
				selector.append("<option value=\"" + values[i].id + "\">"
						+ values[i].name + "</option>");
			}

			if (paramObj.VEClassName != null
					&& $.trim(paramObj.VEClassName) != "") {
				selector.addClass(paramObj.VEClassName);
			} else {
				selector.addClass("select");
			}

			selector.insertBefore($(this));
		} else if (component.type == "combobox") {

		} else if (component.type == "checkbox") {
			if (paramObj != null && paramObj.items != null) {
				var values = paramObj.items;
				for (var i = 0; i < values.length; i++) {
					var chk = $("<input>", {
								"type" : "checkbox",
								"value" : values[i].id,
								"name" : component.formName + "_",
								"label" : values[i].name,
								"checked" : (methods
										.checkItemInGroup((vlu == null
														? paramObj.checkItem
														: vlu), values[i].id)
										? true
										: false),
								"id" : component.formName + "_idx_" + i
							});

					chk.click(function() {
								var chked = $("input[type=checkbox][name="
										+ component.formName + "_][checked]");
								var ids = "";
								var names = "";
								for (var i = 0; i < chked.length; i++) {
									if (i < chked.length - 1) {
										ids += chked[i].val() + ",";
										names += chked[i].attr("label") + ",";
									} else {
										ids += chked[i].val();
										names += chked[i].attr("label");
									}
								}

								$("#" + component.formName).attr("value", ids);
								$("#" + component.formItem)
										.attr("value", names);
							});

					if (paramObj.VEClassName != null
							&& $.trim(paramObj.VEClassName) != "") {
						chk.addClass(paramObj.VEClassName);
					}

					chk.insertBefore($(this));

					$("<label for=\"" + (component.formName + "_idx_" + i)
							+ "\">" + values[i].name + "</label>")
							.insertBefore($(this));
				}

				$("<input>", {
							"type" : "hidden",
							"name" : component.formName,
							"id" : component.formName
						}).insertBefore($(this));
			} else {
				var chk = $("<input>", {
							"type" : "checkbox",
							"value" : component.defaultValue,
							"checked" : (vlu == null
									? component.defaultValue
									: vlu),
							"name" : component.formName,
							"label" : component.label,
							"id" : component.formName
						});

				chk.click(function() {
							if ($(this).attr("checked")
									&& $("#" + paramObj.forItem).length > 0) {
								$("#" + paramObj.forItem).val($(this)
										.attr("label"));
							} else {
								$("#" + paramObj.forItem).val("");
							}
						});

				if (paramObj.VEClassName != null
						&& $.trim(paramObj.VEClassName) != "") {
					chk.addClass(paramObj.VEClassName);
				}

				chk.insertBefore($(this));

				$("<label for=\"" + (component.formName) + "\">"
						+ component.label + "</label>").insertBefore($(this));
			}
		} else if (component.type == "radio") {
			if (paramObj != null && paramObj.items != null) {
				var values = paramObj.items;

				for (var i = 0; i < values.length; i++) {
					var rad = $("<input>", {
						"type" : "radio",
						"value" : values[i].id,
						"name" : component.formName,
						"label" : values[i].name,
						"checked" : ((paramObj.checkItem == values[i].id || values[i].id == vlu)
								? true
								: false),
						"id" : component.formName + "_idx_" + i
					});

					rad.click(function() {
								if ($(this).attr("checked")
										&& $("#" + paramObj.forItem).length > 0) {
									$("#" + paramObj.forItem).val($(this)
											.attr("label"));
								}
							});

					if (paramObj.VEClassName != null
							&& $.trim(paramObj.VEClassName) != "") {
						rad.addClass(paramObj.VEClassName);
					}

					rad.insertBefore($(this));

					$("<label for=\"" + (component.formName + "_idx_" + i)
							+ "\">" + values[i].name + "</label>")
							.insertBefore($(this));
				}
			} else {
				var rad = $("<input>", {
					"type" : "radio",
					"value" : component.defaultValue,
					"checked" : ((paramObj.checkItem == component.defaultValue || component.defaultValue == vlu)
							? true
							: false),
					"name" : component.formName,
					"label" : component.label,
					"id" : component.formName
				});

				rad.click(function() {
							if ($(this).attr("checked")
									&& $("#" + paramObj.forItem).length > 0) {
								$("#" + paramObj.forItem).val($(this)
										.attr("label"));
							}
						});

				if (paramObj.VEClassName != null
						&& $.trim(paramObj.VEClassName) != "") {
					rad.addClass(paramObj.VEClassName);
				}

				rad.insertBefore($(this));

				$("<label for=\"" + (component.formName) + "\">"
						+ component.label + "</label>").insertBefore($(this));

			}
		} else if (component.type == "file") {
			var file = $("<input>", {
						"type" : "file",
						"name" : component.formName,
						"id" : component.formName
					});
			if (paramObj.VEClassName != null
					&& $.trim(paramObj.VEClassName) != "") {
				file.addClass(paramObj.VEClassName);
			}

			file.insertBefore($(this));
		}

		$(this).remove();
	};

	$.fn.analyzingItem4List = function(component, idx) {
		var cmpName;
		var cmpId;
		var cmpValue;
		var cmpLabel;

		if (component.type == "input" || component.type == "hidden"
				|| component.type == "textarea") {
			cmpName = component.formName + "_" + idx;
			cmpId = component.formName + "_" + idx;
			cmpValue = $("#" + component.formName).val();
			cmpLabel = $("#" + component.formName).val();
		} else if (component.type == "date") {
			cmpName = component.formName + "_" + idx;
			cmpId = component.formName + "_" + idx;
			cmpValue = methods.formatTime($("#" + component.formName + "_")
							.val(), "000000");
			cmpLabel = $("#" + component.formName + "_").val();
		} else if (component.type == "select") {
			cmpName = component.formName + "_" + idx;
			cmpId = component.formName + "_" + idx;
			cmpValue = $("#" + component.formName).val();
			cmpLabel = $("#" + component.formName).text();
		} else if (component.type == "combobox") {

		} else if (component.type == "checkbox") {
			if (paramObj != null && paramObj.items != null) {
				cmpName = component.formName + "_" + idx;
				cmpId = component.formName + "_" + idx;
				cmpValue = $("#" + component.formName).val();
				cmpLabel = $("#" + component.forItem).val();
			} else {
				cmpName = component.formName + "_" + idx;
				cmpId = component.formName + "_" + idx;
				cmpValue = $("#" + component.formName).val();
				cmpLabel = $("#" + component.formName).attr("label");
			}
		} else if (component.type == "radio") {
			cmpName = component.formName + "_" + idx;
			cmpId = component.formName + "_" + idx;
			cmpValue = $("#" + component.formName).val();
			cmpLabel = $("#" + component.formName).attr("label");
		} else if (component.type == "file") {

		}

		var ipt = $("<input>", {
					"type" : "hidden",
					"value" : cmpValue,
					"name" : cmpName,
					"id" : cmpId
				});

		$(this).append(ipt);

		$(this).append(cmpLabel);
	};

	/* 初始化信息定义窗口 */
	$.fn.initDialog4List = function(n) {
		var dialogId = n.id + "_dialog";

		if ($("#" + dialogId).length > 0) {
			var tridx = $("#" + n.id).attr("nowEditIdx");
			if ($.trim(tridx) != "") {
				/* 编辑已有内容 */
				$.each(n.items, function(j, m) {
							if (m.type == "hidden") {

							}

							$("#" + m.formName).attr("value",
									$("#" + m.formName + "_" + tridx).val());
						});
			} else {
				/* 新定义内容 */
				$.each(n.items, function(j, m) {
							$("#" + m.formName).attr("value", "");
						});
			}

			$("#" + dialogId).dialog("open");
		} else {
			var div = $("<div>");
			div.attr("class", "formular");
			var table = $("<table border=\"0\">");
			div.append(table);
			$.each(n.items, function(j, m) {
						if (m.type == "hidden") {
							$("<input>", {
										"type" : "hidden",
										"value" : "",
										"name" : m.formName,
										"id" : m.formName
									}).appendTo(div);
						} else {
							var tr = $("<tr>");
							table.append(tr);
							var td1 = $("<td align=\"center\">");
							tr.append(td1);
							td1.append("<label for=\"" + m.formName + "\">"
									+ m.label + "</label>");
							var td2 = $("<td>");
							tr.append(td2);
							var span = $("<span>");

							td2.append(span);
							span.assemblingItem4List(m, null);
						}
					});

			$("<div>", {
						id : dialogId,
						title : n.title
					}).append(div).appendTo("body");

			$("#" + dialogId).dialog({
						autoOpen : open,
						width : n.param.width == null ? 300 : n.param.width,
						height : n.param.height == null ? 400 : n.param.height,
						modal : n.param.modal == null ? true : n.param.modal,
						closeOnEscape : true,
						resizable : true,
						// hide : "explode",
						// show : "slow",
						buttons : [{
									text : " 确定 ",
									click : function(event) {
										$(this).setTableList(n);
										$(this).dialog("close");
									}
								}, {
									text : " 取消 ",
									click : function() {
										$(this).dialog("close");
									}
								}]
					});
		}

		if (n.items != null) {
			$.each(n.items, function(j, m) {
						if ($("span[id=" + m.formName + "]").length > 0) {
							$("span[id=" + m.formName + "]").assemblingItem(m,
									null);
						}
					});
		}
	}

	/**
	 * 增加或重置列表行
	 */
	$.fn.setTableList = function(n) {
		var counter_ = parseInt($("#" + n.id).attr("counter_"));
		var tridx = $("#" + n.id).attr("nowEditIdx");

		/* 编辑操作 */
		if ($.trim(tridx) != "") {
			var trid = n.id + "_tr_" + tridx;
			var tbodytr = $("#" + trid);

			$.each(n.items, function(j, m) {
						if (m.type == "hidden") {
							$("#" + m.formName + "_" + tridx).attr("value",
									$("#" + m.formName).val());
						} else {
							var tdid = n.id + "_tr_" + tridx + "_td_"
									+ m.formName;

							var span = $("<span>");
							span.analyzingItem4List(m, tridx);

							var tbodytrtd = $("#" + tdid);
							tbodytrtd.html("");
							tbodytrtd.append(span);
						}
					});
		} else {
			/* 新定义操作 */
			var trid = n.id + "_tr_" + counter_;
			var idx = counter_;
			var tbodytr = $("<tr>", {
						"id" : trid
					});
			tbodytr.attr("idx", idx);
			$("#" + n.id + ">tbody").append(tbodytr);

			$.each(n.items, function(j, m) {
						if (m.type == "hidden") {
							tbodytr.append("<input>", {
										"type" : "hidden",
										"name" : m.formName + "_" + counter_,
										value : $("#" + m.formName).val()
									});
							$("#" + m.formName).attr("value", "");
						} else {
							var span = $("<span>");
							span.analyzingItem4List(m, counter_);
							var tdid = n.id + "_tr_" + counter_ + "_td_"
									+ m.formName;
							var tbodytrtd = $("<td>", {
										id : tdid,
										align : "center"
									});
							tbodytrtd.append(span);
							tbodytr.append(tbodytrtd);
							$("#" + m.formName).attr("value", "");
						}
					});

			var span = $("<span>");

			var editA = $("<a>");
			span.append(editA);
			editA.attr("href", "javascript:void(0);");
			editA.html("编辑");
			editA.bind("click", function() {
						/* 记录当前编辑行序列 */
						$("#" + n.id).attr("nowEditIdx", idx);
						$(this).initDialog4List(n);
					});
			span.append("&nbsp;");
			var eidtD = $("<a>");
			span.append(eidtD);
			eidtD.attr("href", "javascript:void(0);");
			eidtD.html("删除");
			eidtD.bind("click", function() {
						$(this).listCount(n);
						$("#" + trid).remove();
					});

			var tdid = n.id + "_tr_" + counter_ + "_td_AA";
			var tbodytrtd = $("<td>", {
						id : tdid,
						align : "center"
					});
			tbodytrtd.append(span);
			tbodytr.append(tbodytrtd);

			counter_++;

			$("#" + n.id).attr("counter_", counter_);

			$(this).listCount(n);
		}
	}

	$.fn.listCount = function(n) {
		var idxstr = "";
		$("#" + n.id + ">tbody").find("tr").each(function() {
					idxstr += $(this).attr("idx") + ",";
				});

		$("#" + n.counterName).attr("value", idxstr);
	}

	$.fn.removeReal = function(id, tableName) {

		return false;
	}
})(jQuery);